*****************************************************************
*** Additional programs for Laron K. Williams, "Guns Yield Butter?  An Exploration of Defense Spending Preferences", Journal of Conflict Resolution
***
*** NOTE: run this before running the replication file
*****************************************************************

*******************************************************************************
*** Program to alphabetically sort a variable based on its value label (ccode)
cap program drop labels_ABC
program labels_ABC
  syntax varname
  local lab_name :value label `varlist'
  tempvar new_order
  preserve
    uselabel `lab_name', clear
    sort label
    generate `new_order' = _n
    tempfile order_dictionary
    sort value
    rename value `varlist'
    keep `varlist' `new_order'
    save `"`order_dictionary'"'
  restore
  sort `varlist'
  merge `varlist' using `"`order_dictionary'"'
  drop _merge
  sort `new_order'
end
*******************************************************************************


*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop sub_h
program define sub_h
	setx mean
	di _newline(2) "Create Jobs = 0; Health Spending = Less " 
	setx spend_health_3 1 create_jobs_favor 0 jobs_health_3 0
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 0; Health Spending = More"
	setx spend_health_3 3 create_jobs_favor 0 jobs_health_3 0
	simqi, prval(1 2 3) level(90) 		
	
	di _newline(2) "Create Jobs = 1; Health Spending = Less " 
	setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 1; Health Spending = More"
	setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
	simqi, prval(1 2 3) level(90) 		
end
*******************************************************************************

*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop sub_e
program define sub_e
	setx mean
	di _newline(2) "Create Jobs = 0; Education Spending = Less " 
	setx spend_educ_3 1 create_jobs_favor 0 jobs_educ_3 0
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 0; Education Spending = More"
	setx spend_educ_3 3 create_jobs_favor 0 jobs_educ_3 0
	simqi, prval(1 2 3) level(90) 		
	
	di _newline(2) "Create Jobs = 1; Education Spending = Less " 
	setx spend_educ_3 1 create_jobs_favor 1 jobs_educ_3 1
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 1; Education Spending = More"
	setx spend_educ_3 3 create_jobs_favor 1 jobs_educ_3 3
	simqi, prval(1 2 3) level(90) 		
end
*******************************************************************************

*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop sub_p
program define sub_p
	setx mean
	di _newline(2) "Create Jobs = 0; Pension Spending = Less " 
	setx spend_pensions_3 1 create_jobs_favor 0 jobs_pensions_3 0
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 0; Pension Spending = More"
	setx spend_pensions_3 3 create_jobs_favor 0 jobs_pensions_3 0
	simqi, prval(1 2 3) level(90) 		
	
	di _newline(2) "Create Jobs = 1; Pension Spending = Less " 
	setx spend_pensions_3 1 create_jobs_favor 1 jobs_pensions_3 1
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 1; Pension Spending = More"
	setx spend_pensions_3 3 create_jobs_favor 1 jobs_pensions_3 3
	simqi, prval(1 2 3) level(90) 		
end
*******************************************************************************

*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop sub_u
program define sub_u
	setx mean
	di _newline(2) "Create Jobs = 0; Unemployment Spending = Less " 
	setx spend_unem_3 1 create_jobs_favor 0 jobs_unem_3 0
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 0; Unemployment Spending = More"
	setx spend_unem_3 3 create_jobs_favor 0 jobs_unem_3 0
	simqi, prval(1 2 3) level(90) 		
	
	di _newline(2) "Create Jobs = 1; Unemployment Spending = Less " 
	setx spend_unem_3 1 create_jobs_favor 1 jobs_unem_3 1
	simqi, prval(1 2 3) level(90) 

	di _newline(2) "Create Jobs = 1; Unemployment Spending = More"
	setx spend_unem_3 3 create_jobs_favor 1 jobs_unem_3 3
	simqi, prval(1 2 3) level(90) 		
end
*******************************************************************************


*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop probab
program define probab

* Create jobs = 0: Health Spending
di _newline(2) "Scenario is supportive"
setx $supportive
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

di _newline(2) "Scenario is indifferent"
setx $neither
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

di _newline(2) "Scenario is unsupportive"
setx $unsupportive
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

* Create jobs = 1: Health Spending
* Supportive
tempvar s_pr1_0 s_pr2_0 s_pr3_0 s_pr1_1 s_pr2_1 s_pr3_1 s_diff1 s_diff2 s_diff3
setx $supportive
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`s_pr1_0' `s_pr2_0' `s_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`s_pr1_1' `s_pr2_1' `s_pr3_1') level(90)

gen `s_diff1' = `s_pr1_1' - `s_pr1_0'
qui sum `s_diff1', meanonly
local s1_mean = r(mean)
_pctile `s_diff1', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 1) = " `s1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `s_diff2' = `s_pr2_1' - `s_pr2_0'
qui sum `s_diff2', meanonly
local s2_mean = r(mean)
_pctile `s_diff2', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 2) = " `s2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `s_diff3' = `s_pr3_1' - `s_pr3_0'
qui sum `s_diff3', meanonly
local s3_mean = r(mean)
_pctile `s_diff3', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 3) = " `s3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"


* Neither
tempvar n_pr1_0 n_pr2_0 n_pr3_0 n_pr1_1 n_pr2_1 n_pr3_1 n_diff1 n_diff2 n_diff3
setx $neither
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`n_pr1_0' `n_pr2_0' `n_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`n_pr1_1' `n_pr2_1' `n_pr3_1') level(90)

gen `n_diff1' = `n_pr1_1' - `n_pr1_0'
qui sum `n_diff1', meanonly
local n1_mean = r(mean)
_pctile `n_diff1', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 1) = " `n1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `n_diff2' = `n_pr2_1' - `n_pr2_0'
qui sum `n_diff2', meanonly
local n2_mean = r(mean)
_pctile `n_diff2', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 2) = " `n2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `n_diff3' = `n_pr3_1' - `n_pr3_0'
qui sum `n_diff3', meanonly
local n3_mean = r(mean)
_pctile `n_diff3', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 3) = " `n3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

* Unsupportive
tempvar u_pr1_0 u_pr2_0 u_pr3_0 u_pr1_1 u_pr2_1 u_pr3_1 u_diff1 u_diff2 u_diff3
setx $unsupportive
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`u_pr1_0' `u_pr2_0' `u_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`u_pr1_1' `u_pr2_1' `u_pr3_1') level(90)

gen `u_diff1' = `u_pr1_1' - `u_pr1_0'
qui sum `u_diff1', meanonly
local u1_mean = r(mean)
_pctile `u_diff1', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 1) = " `u1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `u_diff2' = `u_pr2_1' - `u_pr2_0'
qui sum `u_diff2', meanonly
local u2_mean = r(mean)
_pctile `u_diff2', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 2) = " `u2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `u_diff3' = `u_pr3_1' - `u_pr3_0'
qui sum `u_diff3', meanonly
local u3_mean = r(mean)
_pctile `u_diff3', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 3) = " `u3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"
end
*******************************************************************************

*******************************************************************************
*** Program to generate the predicted probabilities for scenarios of spending and create jobs.
capture program drop probab_us
program define probab_us

* Create jobs = 0: Health Spending
di _newline(2) "Scenario is supportive"
setx $supportive_us
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

di _newline(2) "Scenario is indifferent"
setx $neither_us
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

di _newline(2) "Scenario is unsupportive"
setx $unsupportive_us
simqi, fd(prval(1 2 3)) changex(spend_health_3 1 3) level(90)

* Create jobs = 1: Health Spending
* Supportive
tempvar s_pr1_0 s_pr2_0 s_pr3_0 s_pr1_1 s_pr2_1 s_pr3_1 s_diff1 s_diff2 s_diff3
setx $supportive_us
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`s_pr1_0' `s_pr2_0' `s_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`s_pr1_1' `s_pr2_1' `s_pr3_1') level(90)

gen `s_diff1' = `s_pr1_1' - `s_pr1_0'
qui sum `s_diff1', meanonly
local s1_mean = r(mean)
_pctile `s_diff1', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 1) = " `s1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `s_diff2' = `s_pr2_1' - `s_pr2_0'
qui sum `s_diff2', meanonly
local s2_mean = r(mean)
_pctile `s_diff2', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 2) = " `s2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `s_diff3' = `s_pr3_1' - `s_pr3_0'
qui sum `s_diff3', meanonly
local s3_mean = r(mean)
_pctile `s_diff3', perc(5 95)
di _newline(2) "Scenario is supportive"
di "Probability (Y = 3) = " `s3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"


* Neither
tempvar n_pr1_0 n_pr2_0 n_pr3_0 n_pr1_1 n_pr2_1 n_pr3_1 n_diff1 n_diff2 n_diff3
setx $neither_us
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`n_pr1_0' `n_pr2_0' `n_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`n_pr1_1' `n_pr2_1' `n_pr3_1') level(90)

gen `n_diff1' = `n_pr1_1' - `n_pr1_0'
qui sum `n_diff1', meanonly
local n1_mean = r(mean)
_pctile `n_diff1', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 1) = " `n1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `n_diff2' = `n_pr2_1' - `n_pr2_0'
qui sum `n_diff2', meanonly
local n2_mean = r(mean)
_pctile `n_diff2', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 2) = " `n2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `n_diff3' = `n_pr3_1' - `n_pr3_0'
qui sum `n_diff3', meanonly
local n3_mean = r(mean)
_pctile `n_diff3', perc(5 95)
di _newline(2) "Scenario is indifferent"
di "Probability (Y = 3) = " `n3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

* Unsupportive
tempvar u_pr1_0 u_pr2_0 u_pr3_0 u_pr1_1 u_pr2_1 u_pr3_1 u_diff1 u_diff2 u_diff3
setx $unsupportive_us
setx spend_health_3 1 create_jobs_favor 1 jobs_health_3 1
qui simqi, prval(1 2 3) genpr(`u_pr1_0' `u_pr2_0' `u_pr3_0') level(90)

setx spend_health_3 3 create_jobs_favor 1 jobs_health_3 3
qui simqi, prval(1 2 3) genpr(`u_pr1_1' `u_pr2_1' `u_pr3_1') level(90)

gen `u_diff1' = `u_pr1_1' - `u_pr1_0'
qui sum `u_diff1', meanonly
local u1_mean = r(mean)
_pctile `u_diff1', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 1) = " `u1_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `u_diff2' = `u_pr2_1' - `u_pr2_0'
qui sum `u_diff2', meanonly
local u2_mean = r(mean)
_pctile `u_diff2', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 2) = " `u2_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

gen `u_diff3' = `u_pr3_1' - `u_pr3_0'
qui sum `u_diff3', meanonly
local u3_mean = r(mean)
_pctile `u_diff3', perc(5 95)
di _newline(2) "Scenario is unsupportive"
di "Probability (Y = 3) = " `u3_mean' "   and 90% CIs = [" `r(r1)' ",  " `r(r2)' "]"

end
*******************************************************************************
